package com.example.function.integration.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.http.HttpStatus;

import java.io.Serializable;
import java.util.HashMap;

import static com.example.function.integration.constant.CommonConstant.RES_SUCCESS_MSG;

/**
 * @Description：公共返回实体
 * @Author：fengcheng
 * @Date：2024/10/12 09:25
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseBody implements Serializable {
    /**
     * 响应代码
     */
    private String code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应结果
     */
    private Object result;

    public static ResponseBody success(Object data) {
        return success(String.valueOf(HttpStatus.SC_OK), RES_SUCCESS_MSG, data);
    }

    public static ResponseBody success(String code, String message, Object data) {
        return error(code, message, data);
    }

    public static ResponseBody error(String errorCode, String message) {
        return error(errorCode, message, new HashMap<>());
    }

    public static ResponseBody error(String code, String message, Object data) {
        ResponseBody ResponseBody = new ResponseBody();
        ResponseBody.setCode(code);
        ResponseBody.setMessage(message);
        ResponseBody.setResult(data);
        return ResponseBody;
    }

    public static ResponseBody error(String message) {
        return error(String.valueOf(HttpStatus.SC_BAD_REQUEST), message, new HashMap<>());
    }
}
